package com.tax.controller;


import com.tax.config.exception.ApiException;
import com.tax.config.jwt.JwtUserInfo;
import com.tax.config.page.PageResult;
import com.tax.config.response.Response;
import com.tax.dto.req.*;
import com.tax.dto.res.LoginRes;
import com.tax.dto.res.UserInfoRes;
import com.tax.dto.res.UserPageInfo;
import com.tax.service.ITdUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 用户管理
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private ITdUserService iTdUserService;

    /**
     * 用户输入手机号+密码登录
     * 用户输入手机号+验证码登录
     * @returns
     */
    @ApiOperation(value = "用户登录", notes = "用户登录",response = LoginRes.class)
    @RequestMapping(value = "/login",method=RequestMethod.POST)
    public Response<LoginRes> appLogin(@Validated @RequestBody LoginReq req) throws ApiException {
       LoginRes res=iTdUserService.appLogin(req);
        return new Response<>(res);
    }

    @ApiOperation(value = "根据token获取信息", response = JwtUserInfo.class)
    @RequestMapping(value = "/v1/jwtUserInfo",method=RequestMethod.POST)
    public Response<JwtUserInfo> v2jwtUserInfo(@Validated @RequestBody TokenReq req){
        Response<JwtUserInfo> res=iTdUserService.v2jwtUserInfo(req);
        return res;
    }

    /**
     * 获取用户列表信息
     * @return
     */
    @ApiOperation(value="获取用户列表信息",notes = "获取用户列表信息",response = UserPageInfo.class,responseContainer = "List")
    @RequestMapping(path = "/userPage",method=RequestMethod.GET)
    public Response<PageResult<UserPageInfo>> userPage(@Validated UserPageReq req){
        PageResult<UserPageInfo> pageResult=iTdUserService.userPage(req);
        return new Response<>(pageResult);
    }

    /**
     * 获取用户信息
     * @return
     */
    @ApiOperation(value="获取用户信息",notes = "获取用户信息",response = UserInfoRes.class)
    @RequestMapping(path = "/getUserInfo",method=RequestMethod.GET)
    public Response<UserInfoRes> getUserInfo(@Validated UserInfoReq req){
        UserInfoRes res=iTdUserService.getUserInfo(req);
        return new Response<>(res);
    }

    @ApiOperation(value = "修改用户密码",notes = "修改用户密码",response = UserInfoRes.class)
    @RequestMapping(value = "/editPassword",method=RequestMethod.POST)
    public Response<UserInfoRes> editPassword(@Validated @RequestBody EditPasswordReq req) throws ApiException {
        UserInfoRes res=iTdUserService.editPassword(req);
        return new Response<>(res);
    }
}
